package cn.lijiajia3515.cairo.system.modules.file2;

import io.minio.StatObjectResponse;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

import java.util.stream.Collectors;

/**
 * 文件转换器
 */
public class FileConverter {
	/**
	 * 文件状态
	 * @param response
	 * @return
	 */
	public static FileStat convert(StatObjectResponse response) {
		return FileStat.builder()
			.etag(response.etag())
			.version(response.versionId())
			.lastModified(response.lastModified().toLocalDateTime())
			.size(response.size())
			.headers(response.headers().names().stream().map(x -> Tuples.of(x, response.headers().values(x))).collect(Collectors.toMap(Tuple2::getT1, Tuple2::getT2)))
			.userMetadata(response.userMetadata())
			.bucket(response.bucket())
			.region(response.region())
			.object(response.object())
			.build();
	}
}
